﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace SSS.Core.Model
{

    public class Purchase
    {
        #region 字段
        private DateTime purchaseTime; //采购到货时间

        public DateTime PurchaseTime
        {
            get { return purchaseTime; }
            set { purchaseTime = value; }
        }

        private string              purchaseUserId; //采购负责人id
        public string PurchaseUserId
        {
            get { return purchaseUserId; }
            set { purchaseUserId = value; }
        }

        private string              storageUserId;  //入库负责人id
        public string StorageUserId
        {
            get { return storageUserId; }
            set { storageUserId = value; }
        }

        private int                 depotNo; //仓库编号
        public int DepotNo
        {
            get { return depotNo; }
            set { depotNo = value; }
        }

        private string              depotName;
        public string DepotName
        {
            get { return depotName; }
            set { depotName = value; }
        }
        private List<Inventory>     inventoryList;
        public List<Inventory> InventoryList
        {
            get { return inventoryList; }
            set { inventoryList = value; }
        }

        private string format = "{0}\"purchaseTime\":{1},\"purchaseUserId\":{2},\"storageUserId\":{3},\"depotNo\":{4},\"depotName\":{5},\"inventoryList\":{6}{7}";
        #endregion

 
        #region 构造函数

        public Purchase(DateTime purchaseTime, string purchaseUserId, string storageUserId, int depotNo, string depotName, List<Inventory> inventoryList)
        {
            this.purchaseTime = purchaseTime;
            this.purchaseUserId = purchaseUserId;
            this.storageUserId = storageUserId;
            this.depotNo = depotNo;
            this.depotName = depotName;
            this.inventoryList = inventoryList;
        }

        #endregion

        #region 成员函数

        public override string ToString()
        {
            string inventoryListStr = "[";
            for (int i = 0; i < inventoryList.Count; i++)
            {
                if ( i < inventoryList.Count -1 )
                    inventoryListStr += inventoryList[ i ].ToString() + ",";
                else
                    inventoryListStr += inventoryList[ i ].ToString();
            }
            inventoryListStr += "]";

            return String.Format( format,
                "{",
                purchaseTime == DateTime.MinValue ? "null" : String.Concat("\"",purchaseTime.ToString(),"\""), 
                purchaseUserId == null ? "null" : String.Concat("\"",purchaseUserId,"\""), 
                storageUserId == null ? "null" : String.Concat("\"",storageUserId,"\""), 
                depotNo == 0 ? "0" : String.Concat("\"",depotNo.ToString(),"\""),
                depotName == null ? "null" : String.Concat("\"",depotName,"\""),
                inventoryList == null ? "null" : inventoryListStr,
                "}");
        }

        public Purchase GetPurchaseByJson( string Json )
        {

            return new Purchase();
        }

        #endregion
    }
}
